package org.example.judge.oj;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.File;
import java.io.InputStream;
import java.util.Random;

/**
 * 单个测试用例运行结果
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class JudgeResult {
    /**
     * 运行成功
     */
    public static final int ACCEPTED = 0;
    /**
     * 答案错误
     */
    public static final int WRONG_ANSWER = 1;
    /**
     * 超时
     */
    public static final int TIME_LIMIT_EXCEEDED = 2;
    /**
     * 内存超限
     */
    public static final int MEMORY_LIMIT_EXCEEDED = 3;
    /**
     * 编译失败
     */
    public static final int COMPILE_ERROR = 4;
    /**
     * 运行失败
     */
    public static final int RUNTIME_ERROR = 5;
    /**
     * 内部错误
     */
    public static final int INNER_ERROR = 6;
    /**
     * 运行中
     */
    public static final int RUNNING = 7;
    /**
     * 状态码
     */
    private Integer status;
    /**
     * 运行失败的详细描述
     */
    private String errorMsg;
    /**
     * 结果描述
     */
    private String msg;

    /**
     * 输出结果
     */
    private String data;

    private long time;
    private long memory;
    private File output;

    public JudgeResult(int status, String msg, String errorMsg) {
        this.status = status;
        this.msg = msg;
        this.errorMsg = errorMsg;
    }

    public static JudgeResult Accepted(long time, long memory, File output) {
        return new JudgeResult(ACCEPTED, null, "答案正确", null, time, memory, output);
    }

    public static JudgeResult WrongAnswer(long time, long memory, String data) {
        return new JudgeResult(WRONG_ANSWER, null, "答案错误", data, time, memory, null);
    }

    public static JudgeResult TimeLimitExceeded(long time, long memory) {
        return new JudgeResult(TIME_LIMIT_EXCEEDED, null, "运行时间超时", null, time, memory, null);
    }

    public static JudgeResult MemoryLimitExceeded(long time, long memory) {
        return new JudgeResult(MEMORY_LIMIT_EXCEEDED, null, "运行内存超限", null, time, memory, null);
    }

    public static JudgeResult CompileError(String errorMsg) {
        return new JudgeResult(COMPILE_ERROR, "编译错误", errorMsg);
    }

    public static JudgeResult RuntimeError(String errorMsg) {
        return new JudgeResult(RUNTIME_ERROR, "运行错误", errorMsg);
    }

    public static JudgeResult InnerError(){return new JudgeResult(INNER_ERROR,"内部错误",null);}

    public static JudgeResult Running(){return new JudgeResult(RUNNING,"运行中",null);}
}
